package com.hao.shirojwt.util.thread.impl;


import com.hao.shirojwt.util.thread.ThreadPoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

@Slf4j
public class ThreadPoolServiceImpl implements ThreadPoolService {

    @Resource
    private ExecutorService executorService;

    @Override
    public void execute(Runnable runnable) {
        executorService.execute(runnable);
    }

    @Override
    public Future<?> submit(Runnable runnable) {
        return executorService.submit(runnable);
    }

    @Override
    public <T> Future submit(Callable<T> callable) {
        return executorService.submit(callable);
    }

    @Override
    public <T> List<Future<T>> invokeAll(ArrayList<Callable<T>> callables) {
        List<Future<T>> futures = null;
        try{
            futures = executorService.invokeAll(callables);
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
        return futures;
    }
}
